package breeze.pixel.weather.cityhistory.model;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

import breeze.pixel.weather.R;
import breeze.pixel.weather.apps_util.views.mtextview.MTextView;

public class CityHistoryAdapter extends BaseAdapter {

    private final Context context;
    private final List<CityInfo> datas;

    public CityHistoryAdapter(Context context, List<CityInfo> data){
        this.context = context;
        this.datas = data;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CityInfo info = datas.get(position);
        ViewHolder holder;
        if(convertView==null){
            holder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.morecity_item,null);
            holder.Name=convertView.findViewById(R.id.morecityitemTextView_title);
            holder.ID=convertView.findViewById(R.id.morecityitemTextView_id);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.Name.setText(info.getCityName());
        holder.ID.setText(info.getCityID());
        return convertView;
    }

    static class ViewHolder{
        MTextView Name,ID;
    }
}
